// 引入一个包
const path = require('path');
const HTMLWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
//webpack所有的配置信息都应该写在下面
module.exports = {
  entry: './src/index.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
    environment:{
      arrowFunction:false,
      const:false
    }
  },
  module: {
    //指定加载的规则
    rules: [
      {
        test: /\.ts$/,
        //要使用的loader
        use: [
          {
          loader: "babel-loader",
          options: {
            presets: [
              //指定环境的插件
             [
               "@babel/preset-env",
              {
                targets: {
                  "chrome": "58",
                  "ie":"11"
                },
                "corejs": "3",
                "useBuiltIns": "usage"
              }
            ]
            ]
          }
        },
          'ts-loader'
        ],
        //要排除的文件
        exclude: /node-modules/
      },
      {
        test:/\.less$/,
        use:[
          "style-loader",
          "css-loader",
          //引入postcss
          {
           loader:"postcss-loader",
           options:{
             postcssOptions:{
               plugins:[
                 ["postcss-preset-env",
                 {
                   browsers:"last 2 version"
                 }
               ]
              ]
             }
           }
          },
          "less-loader"
        ]
      }
    ]
  },
  plugins: [
    new HTMLWebpackPlugin({
      template:"./src/index.html"
    }),
    new CleanWebpackPlugin(),
  ],
  resolve: {
    extensions: ['.ts', ".js"]
  }
}